package com.mark.anto.bootstrap;

import com.mark.anto.autoconfigure.HelloWorldAutoConfiguration;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.Assert;

/**
 * @Description: {@link EnableAutoConfiguration} 引导类
 * @Author: Mark
 * @CreateDate: 2019/9/1 10:58
 * @Version: 3.00.001
 * @Copyright : 豆浆油条个人非正式工作室
 *
 * @see .\resources\META-INF\spring.factories
 * @see HelloWorldAutoConfiguration
 */
@EnableAutoConfiguration
public class EnableAutoConfigurationBootstrap {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = new SpringApplicationBuilder(EnableAutoConfigurationBootstrap.class)
                .web(WebApplicationType.NONE)
                .run(args);

        //从上下文中获取Bean
        String bean = context.getBean("helloWorld", String.class);
        Assert.notNull(bean, "获取到Bean为为空！");
        System.out.println(bean);

        //关闭上下文
        context.close();
    }
}
